<?php
require_once ('../../Connections/agriculture.php');
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>留言板用户注册</title>
</head>

<body>

<?php
if ($_POST ['pass'] != "") {
	mysql_select_db ( $database_agriculture, $agriculture );
	
	$user = $_POST ['user'];
	$pass = $_POST ['pass'];
	$email = $_POST ['email'];
	
	//查询账号是否被注册
	$checkSql = "select * from poster where poster_user='" . $user . "'";
	$checkSqlResult = mysql_query ( $checkSql );
	$row_checkSqlResult = mysql_fetch_assoc ( $checkSqlResult );
	
	//若账号未被注册,则进行注册
	if (! $row_checkSqlResult) {
		$regSql = "insert into poster values(null,'" . $user . "','" . $pass . "','" . $email . "')";
		$regResult = mysql_query ( $regSql );
		if ($regResult) {
			echo '注册成功!';
			echo "<meta http-equiv=refresh content='2; url=login.php'>";
		}
	} else {
		echo '账号已经被注册,请更换注册账号';
	}
}
?>
<form id="form1" name="form1" method="post" action=""><label>账号 <input
	name="user" type="text" id="user" /> (*) </label>
<p><label>邮箱 <input name="email" type="text" id="email" /> </label></p>
<p><label>密码 <input name="pass" type="password" id="pass" /> </label>
(*)</p>
<p><label></label> <label>密码确认 <input name="pass2" type="password"
	id="pass2" /> (*) </label></p>
<p><label> <input type="submit" name="Submit" value="确定"
	onclick="return checkPass(form1)" /> </label> <label> <input
	type="reset" name="Submit2" value="重置" /> </label></p>
</form>

<script language="javascript">
function checkPass(){

	var pass1=form1.pass.value;
	var pass2=form1.pass2.value;
	var user=form1.user.value;
	
	if(user==""){
		alert("账号不能为空,请重新输入!");
		form1.user.focus();
		return false;
	}else{
		if(pass1==pass2){
			if(pass1==""){
				alert("密码不能为空,请重新输入!");
				form1.pass.focus();
				return false;
			}
			return true;
		}else{
			alert("再次密码不一致,请重新输入!");
			form1.pass.value="";
			form1.pass2.value="";
			form1.pass.focus();
			return false;
		}
	}
	return true;
}
</script>

</body>
</html>
